# from urllib import request,parse,error

# responce = request.urlopen(r'http://www.baidu.com')
# f = open('./respance', 'w')
# f.write(responce.read().decode('utf-8')) #对获取到的源码进行解码

# data = bytes(parse.urlencode({'hello':'world'}), encoding='utf-8')
# response = request.urlopen(r'http://httpbin.org/post', data=data) #模拟post请求
# print(response.read().decode('utf-8'))

# 超时处理
# try:
#     response = request.urlopen(r'http://httpbin.org/get', timeout=1) #模拟get请求
#     print(response.read().decode('utf-8'))
# except error.URLError:
#     print('time out!')

# response = request.urlopen(r'http://www.baidu.com')
# print(response.getheaders())
# print(response.getheader('Date'))

# url = 'http://www.douban.com'
# # 模拟头部
# headers = {
#     'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36'
# }
# # 创建请求对象
# req = request.Request(url=url, headers=headers)
# # 发送请求
# response = request.urlopen(req)
# print(response.read().decode('utf-8'))


